package scope;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    public static void main(String[] args) {
     //被spring管理的bean，默认作用域是单例的（singleton）
     //容器启动的时候，所有的单例bean都会被实例化出来
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-scope.xml");
        UserServiceForScope user = context.getBean("user", UserServiceForScope.class);
        user.m();

        UserServiceForScope user2 = context.getBean("user", UserServiceForScope.class);
        user2.m();

        System.out.println(user==user2);

        //原型作用域的bean，在容器启动时没有被实例化出的，每个用getBean获取对象的时候，就创建一个新的对象出来
        UserServiceForScope user3 = context.getBean("user3", UserServiceForScope.class);
        user3.m();
        UserServiceForScope user4 = context.getBean("user3", UserServiceForScope.class);
        user4.m();
        System.out.println(user3==user4);
    }
}
